package com.formulas.component.dto;

import java.io.Serial;

/**
 * 对呼叫者的响应
 * @author yiwannuofulasi
 * @date 2023/6/2 10:19
 */
public class Response extends DTO{

    @Serial
    private static final long serialVersionUID = 1L;

    /**是否成功**/
    private boolean success;
    /**错误代码**/
    private String errCode;
    /**错误消息**/
    private String errMessage;

    /**
     * 判断是否成功
     * @return boolean
     */
    public boolean isSuccess() {
        return success;
    }

    /**
     * 设置是否成功
     * @param success boolean
     */
    public void setSuccess(boolean success) {
        this.success = success;
    }

    /**
     * 获取错误代码
     * @return String
     */
    public String getErrCode() {
        return errCode;
    }

    /**
     * 设置错误代码
     * @param errCode String
     */
    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    /**
     * 获取错误消息
     * @return String
     */
    public String getErrMessage() {
        return errMessage;
    }

    /**
     * 设置错误消息
     * @param errMessage String
     */
    public void setErrMessage(String errMessage) {
        this.errMessage = errMessage;
    }

    /**
     * Response#toString()
     * @return String
     */
    @Override
    public String toString() {
        return "Response [success=" + success + ", errCode=" + errCode + ", errMessage=" + errMessage + "]";
    }

    /**
     * 构建成功响应
     * @return Response
     */
    public static Response buildSuccess() {
        Response response = new Response();
        response.setSuccess(true);
        return response;
    }

    /**
     * 构建错误响应
     * @param errCode 错误代码
     * @param errMessage 错误消息
     * @return Response
     */
    public static Response buildFailure(String errCode, String errMessage) {
        Response response = new Response();
        response.setSuccess(false);
        response.setErrCode(errCode);
        response.setErrMessage(errMessage);
        return response;
    }
}
